$(function () {
	$('#searchBtn').on('tap', function () {
		var keyword = $(this).siblings('input').val();
		// console.log(keyword);
		if (!keyword) return alert("请输入您喜欢的商品");

		if (localStorage.getItem('keywords')) {
			var keywords = JSON.parse(localStorage.getItem("keywords"));
			keywords.push(keyword);
			localStorage.setItem("keywords", JSON.stringify(keywords));
		} else {
			localStorage.setItem("keywords", JSON.stringify([keyword]));
		}

		location.href = "search-list.html?key=" + keyword;
	});


	if (localStorage.getItem("keywords")) {
		var keywords = JSON.parse(localStorage.getItem("keywords"));
		$("#historySearch").html(template('historySearchTpl', {data: keywords}));
	}

	$("#clearHistory span").on('tap', function() {
		localStorage.removeItem("keywords");
		$('#historySearch').html('');
	})
});